package com.site.wisdom_construction.controller.publicModule;

import com.site.wisdom_construction.responseEntity.JsonResult;
import com.site.wisdom_construction.responseEntity.OneDataResult;
import com.site.wisdom_construction.responseEntity.Page;
import com.site.wisdom_construction.service.publicModule.ProfessionalTypesService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @Author daiyifei
 * @Date 2022/5/26
 * @Description
 */
@Api(tags = "公共培训课程专业类型接口")
@RestController
@RequestMapping("ProfessionalTypes")
@CrossOrigin
public class ProfessionalTypesController {
    @Autowired
    private ProfessionalTypesService professionalTypesService;


    @ApiOperation(value = "增加专业类型信息", notes = "测试数据:")
    @PostMapping("/insertProfessionalTypes")
    public JsonResult insertProfessionalTypes(@RequestBody Map map){
        JsonResult jsonResult = new JsonResult();
        int i = professionalTypesService.insertProfessionalTypes(map);
        if (i==1){
            jsonResult.setCode(200);
            jsonResult.setMessage("成功录入专业类型信息!");
        }else {
            jsonResult.setCode(20006);
            jsonResult.setMessage("录入专业类型信息失败!");
        }
        return jsonResult;
    }

    @ApiOperation(value = "删除专业类型信息", notes = "测试数据:")
    @PostMapping("/deleteProfessionalTypes")
    public JsonResult deleteProfessionalTypes(@RequestBody Map map){
        JsonResult jsonResult = new JsonResult();
        int i = professionalTypesService.deleteProfessionalTypes(map);
        if (i==1){
            jsonResult.setCode(200);
            jsonResult.setMessage("成功删除专业类型信息!");
        }else {
            jsonResult.setCode(20006);
            jsonResult.setMessage("删除专业类型信息失败!");
        }
        return jsonResult;
    }

    @ApiOperation(value = "修改专业类型信息", notes = "测试数据:")
    @PostMapping("/updateProfessionalTypes")
    public JsonResult updateProfessionalTypes(@RequestBody Map map){
        JsonResult jsonResult = new JsonResult();
        int i = professionalTypesService.updateProfessionalTypes(map);
        if (i==1){
            jsonResult.setCode(200);
            jsonResult.setMessage("成功修改专业类型信息!");
        }else {
            jsonResult.setCode(20006);
            jsonResult.setMessage("修改专业类型信息失败!");
        }
        return jsonResult;
    }

    @ApiOperation(value = "分页模糊查询专业类型信息", notes = "测试数据:")
    @PostMapping("/findProfessionalTypesByPage")
    public Page findProfessionalTypesByPage(@RequestBody Map map) {
        Page page = new Page();
        page.setPageNo((Integer) map.get("pageNo"));
        page.setPageSize((Integer) map.get("pageSize"));
        page.setTotal(professionalTypesService.Total(map));
        page.setItems(professionalTypesService.findProfessionalTypesByPage(map));
        return page;
    }

    @ApiOperation(value = "下拉框查询专业类型信息", notes = "测试数据:")
    @PostMapping("/selectProfessionalTypes")
    public OneDataResult selectProfessionalTypes(@RequestBody Map map) {
        OneDataResult oneDataResult = new OneDataResult();
        oneDataResult.setData(professionalTypesService.selectProfessionalTypes(map));
        return oneDataResult;
    }
}
